#!/usr/bin/env python3
# encoding=utf-8
# import start_solver
import vision
import tkinter as tk
import time
import mission
import plan
import threading

root = tk.Tk(className='cube solver')

root.bind('<Control-Alt-w>',lambda event: mission.add(['Rise']))
root.bind('<Control-Alt-e>',lambda event: mission.add(['Drop']))
root.bind('<Control-Up>',lambda event: mission.add(['Le']))
root.bind('<Control-Down>',lambda event: mission.add(['Lc'])) 
root.bind('<Alt-Up>',lambda event: mission.add(['Re'])) 
root.bind('<Alt-Down>',lambda event: mission.add(['Rc'])) 

root.bind('<Alt-u>',lambda event: mission.add(['U1']))
root.bind('<Control-u>',lambda event: mission.add(['U3'])) 
root.bind('<Alt-Control-u>',lambda event: mission.add(['U2'])) 

root.bind('<Alt-d>',lambda event: mission.add(['D1']))
root.bind('<Control-d>',lambda event: mission.add(['D3'])) 
root.bind('<Alt-Control-d>',lambda event: mission.add(['D2'])) 

root.bind('<Alt-l>',lambda event: mission.add(['L1']))
root.bind('<Control-l>',lambda event: mission.add(['L3'])) 
root.bind('<Alt-Control-l>',lambda event: mission.add(['L2'])) 

root.bind('<Alt-r>',lambda event: mission.add(['R1']))
root.bind('<Control-r>',lambda event: mission.add(['R3'])) 
root.bind('<Alt-Control-r>',lambda event: mission.add(['R2'])) 

root.bind('<Alt-b>',lambda event: mission.add(['B1']))
root.bind('<Control-b>',lambda event: mission.add(['B3'])) 
root.bind('<Alt-Control-8>',lambda event: mission.add(['B2'])) 

root.bind('<Alt-f>',lambda event: mission.add(['F1']))
root.bind('<Control-f>',lambda event: mission.add(['F3'])) 
root.bind('<Alt-Control-f>',lambda event: mission.add(['F2'])) 

root.bind('<Control-Alt-o>',lambda event: mission.add(['Odrive'])) 
root.bind('<Control-i>',lambda event: mission.add(['Cal0'])) 
root.bind('<Alt-i>',lambda event: mission.add(['Cal1'])) 
root.bind('<q>',lambda event: mission.add(['OdDis'])) 
root.bind('<Control-Alt-q>',lambda event: mission.add(['OdEn'])) 

root.bind('<Control-Left>',lambda event: mission.add(['Od0R1'])) 
root.bind('<Shift-Left>',lambda event: mission.add(['Od0R2'])) 
root.bind('<Shift-Right>',lambda event: mission.add(['O d0R2'])) 
root.bind('<Control-Right>',lambda event: mission.add(['Od0R3'])) 
root.bind('<Alt-Left>',lambda event: mission.add(['Od1R1'])) 
root.bind('<Alt-Shift-Left>',lambda event: mission.add(['Od1R2'])) 
root.bind('<Alt-Shift-Right>',lambda event: mission.add(['Od1R2'])) 
root.bind('<Alt-Right>',lambda event: mission.add(['Od1R3'])) 

root.bind('<Control-Alt-j>',lambda event: mission.add(['Scan_test'])) 
root.bind('<space>',lambda event: mission.add(['Final'])) 


temp = tk.Button(root, text='up', command=lambda: mission.add(['Rise']), width=10)
temp.grid(row=0, column=0, columnspan=3)

temp = tk.Button(root, text='down', command=lambda: mission.add(['Drop']), width=10)
temp.grid(row=1, column=0, columnspan=3)

temp = tk.Button(root, text='Cal0', command=lambda: mission.add(['Cal0']), width=10)
temp.grid(row=2, column=0, columnspan=1)

temp = tk.Button(root, text='Cal1', command=lambda: mission.add(['Cal1']), width=10)
temp.grid(row=2, column=1, columnspan=1)


temp = tk.Button(root, text='scan', command=lambda: mission.add(['Scan_test']), width=30)
temp.grid(row=3, column=0, columnspan=3)

temp = tk.Button(root, text='execute', command=lambda: mission.add(['Final']), width=30)
temp.grid(row=4, column=0, columnspan=3)

temp = tk.Button(root, text='exit', command=lambda: root.destroy(), width=30)
temp.grid(row=5, column=0, columnspan=3)

queue_label = tk.Label(root, text=' ', width=30,wraplength=200, justify = 'left')
queue_label.grid(row=9, column=0, columnspan=3, rowspan=3)


def update_queue_label():
    while True:
        queue_label['text'] = 'hardware<< '+mission.get_queue()
        time.sleep(0.03)


queue_t = threading.Thread(target=update_queue_label)
queue_t.daemon = True
queue_t.start()
root.mainloop()

if __name__ == '__main__':
    pass
